import pandas as pd
from matplotlib import pyplot as plt
import numpy as np

df_1 = pd.DataFrame(np.ones((2,4)), index=["A", "B"], columns=list("abcd"))
print("1---", df_1)

df_2 = pd.DataFrame(np.zeros((3,4)), index=["A", "B", "C"], columns=list("xyxz"))
print("2---", df_2)

df_3 = pd.DataFrame(np.zeros((3,3)), columns=list("fax"))
print("3---", df_3)

print("4---", df_1.merge(df_3, on="a"))

df_3.loc[1, "a"] = 1
print("4---", df_3)

print("5---\n", df_1.merge(df_3, on="a"))

df_4 = pd.DataFrame(np.arange(9).reshape((3,3)), columns=list("fax"))
print("6---", df_4)

print("7---", df_1.merge(df_4, on="a")) # 操作a列

df_1.loc["A", "a"] = 109
print("8---", df_1)

print("9---", df_1.merge(df_4, on="a")) # 操作a列

print("10---", df_1.merge(df_4, on="a", how="inner")) # 内联接，默认的

print("11---", df_1.merge(df_4, on="a", how="outer")) # 外联接

print("12---", df_1.merge(df_4, on="a", how="left")) # 左联接

print("12---", df_1.merge(df_4, on="a", how="right")) # 右联接